//
//  AppViewController.m
//  moon
//
//  Created by beyself on 16/6/15.
//  Copyright © 2016年 beyself. All rights reserved.
//
#import "Utils.h"
#import "AppViewController.h"
#import "ClassListViewController.h"
#import "UserSpaceViewController.h"

@interface AppViewController ()

@end

@implementation AppViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = BG;
    
    UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    negativeSpacer.width = -5;
    self.navigationItem.leftBarButtonItems = @[negativeSpacer,
                                               [[UIBarButtonItem alloc] initWithCustomView:[UIButton buttonWithType:UIButtonTypeCustom]]];
    
    if ([[[UIDevice currentDevice]systemVersion]floatValue]>=7.0) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }
    
    for(int i = 0; i < 2; i++)
    {
        UIButton* button  = [UIButton buttonWithType:UIButtonTypeCustom];
        button.tag = 2100 + i;
        button.frame = CGRectMake(40, 10 + 70*i, SCREEN_WIDTH - 50, 60);
        button.titleLabel.font = FONT_15;
        button.titleEdgeInsets = UIEdgeInsetsMake(0, 40, 0, 0);
        button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [button setTitleColor:TEXT forState:UIControlStateNormal];
        [button setBackgroundImage:[Utils imageFromColor:WHITE] forState:UIControlStateNormal];
        [button setBackgroundImage:[Utils imageFromColor:LINE] forState:UIControlStateHighlighted];
        [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:button];
        
        UIImageView* imageview = [[UIImageView alloc] init];
        imageview.frame = CGRectMake(10, 10 + 70*i, 60, 60);
        [self.view addSubview:imageview];
        
        if(i == 0)
        {
            [button setTitle:@"课程表" forState:UIControlStateNormal];
            imageview.image = [UIImage imageNamed:@"icon_timetable"];
        }
/*        else if(i == 1)
        {
            [button setTitle:@"亲子互动" forState:UIControlStateNormal];
            imageview.image = [UIImage imageNamed:@"icon_parenting"];
        }
        else if(i == 2)
        {
            [button setTitle:@"趣味游戏" forState:UIControlStateNormal];
            imageview.image = [UIImage imageNamed:@"icon_game"];
        }
        else if(i == 3)
        {
            [button setTitle:@"孩子的轨迹" forState:UIControlStateNormal];
            imageview.image = [UIImage imageNamed:@"icon_path"];
        }*/
        else if(i == 1)
        {
            [button setTitle:@"成长相册" forState:UIControlStateNormal];
            imageview.image = [UIImage imageNamed:@"icon_photo"];
        }
        
        UIButton* arrow = [UIButton buttonWithType:UIButtonTypeCustom];
        arrow.frame = CGRectMake(SCREEN_WIDTH - 88, 0, 48, 60);
        [arrow setImage:[UIImage imageNamed:@"ic_arrow"] forState:UIControlStateNormal];
        [button addSubview:arrow];
    }
}

- (void) buttonClick:(UIButton*)btn
{
    if(btn.tag == 2100)
    {
        ClassListViewController* subview = [[ClassListViewController alloc] init];
        subview.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:subview animated:YES];
    }
    else if(btn.tag == 2101)
    {
        UserSpaceViewController* subview = [[UserSpaceViewController alloc] init];
        subview.hidesBottomBarWhenPushed = YES;
        subview.mUserId = [APPDELEGATE.mMemberInfo[@"id"] description];
        [self.navigationController pushViewController:subview animated:YES];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
@end
